package cn.hnevc.xiaohui;
//使用StringBuffer 增减改
public class ExampleTest16 {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
    System.out.println("StringBuffer添加");
    add();
    System.out.println("StringBuffer删除");
    remove();
    System.out.println("StringBuffer修改");
   alter();
	}
	//增加
 public static void add() {
	 StringBuffer stringBuffer =new StringBuffer();//定义一个字符串缓冲区
	 stringBuffer.append("abcdefg");//在末尾添加字符串
	 System.out.println("append添加结果："+stringBuffer);
	 stringBuffer.insert(2, "123456");
	 System.out.println("insert添加结果："+stringBuffer);
 }
 //删除
 public static void remove(){
	 StringBuffer stringBuffer =new StringBuffer("abcdefg");
	 stringBuffer.delete(1,5);
	 System.out.println("delete删除结果："+stringBuffer);
	 stringBuffer.deleteCharAt(1);
	 System.out.println("deleteCharAt删除的结果："+stringBuffer);
	 //将所有字符串清空
	 stringBuffer.delete(0,stringBuffer.length());
	 System.out.println("delete清空结果："+stringBuffer); 
 }
 public static void alter() {
	 StringBuffer stringBuffer =new StringBuffer("abcdefg");
	 stringBuffer.setCharAt(1,'x');//修改指定位置
	 System.out.println("setCharAt修改指定位置的结果："+stringBuffer);
	 stringBuffer.replace(0,2,"wechat");
	 System.out.println("replace修改指定位置的结果："+stringBuffer);
	 System.out.println("字符串翻转结果："+stringBuffer.reverse());
}
 }
